<template>
	<view class="binding-btn" @click="bindingClick">
		<text>快捷绑定</text>
	</view>
</template>

<script>
	export default {
		methods: {
			bindingClick() {

				//相关示例代码：（该代码会打开支付宝授权，授权之后会在支付宝中打开你所设置的【回调地址】网页）

				//***********************
				//***url授权地址由后端拼接也可以前端写死***
				//***以下是一个拼接示例，仅需修改app_id的值和redirect_uri的值***
				//***app_id是商户的APPID，redirect_uri是页面跳回地址（授权成功之后会在支付宝中打开这个地址）***
				//***********************
				
				
				
				//相关示例代码：（该代码会打开支付宝授权，授权之后会在支付宝中打开你所设置的【回调地址】网页）
				
				//***********************
				//***url授权地址由后端拼接也可以前端写死***
				//***以下是一个拼接示例，仅需修改app_id的值和redirect_uri的值***
				//***app_id是商户的APPID，redirect_uri是页面跳回地址（授权成功之后会在支付宝中打开这个地址）***
				//***********************
				/* let urls='https://openauth.alipay.com/oauth2/publicAppAuthorize.htm
				?app_id=2021001183611007
				&scope=auth_userinfo
				&redirect_uri=https://shandianlaoshi.com/api/user/zfb_url';
				urls=encodeURIComponent(urls);//将地址编码成浏览器访问的格式 */
				

				let appId = '2021003181612006'
				let scope = 'auth_user'
				//let redirectUrl = 'http://47.106.223.49/demoZfb.html'
				let redirectUrl = 'http://47.106.223.49/zfb/index.html'
				let androidPrefix = 'alipays://platformapi/startapp?appId=20000067&url='
				let iosPrefix = 'alipay://platformapi/startapp?appId=20000067&url='
				
				/* let urls = 'https://openauth.alipay.com/oauth2/publicAppAuthorize.htm?app_id=2021003181612006&scope=auth_userinfo&redirect_uri=http://47.106.223.49/demoZfb.html' */
				let urls = "https://openauth.alipay.com/oauth2/publicAppAuthorize.htm?app_id=" + appId +
					"&scope=" + scope +
					"&redirect_uri=" + redirectUrl
				urls = encodeURIComponent(urls) //将地址编码为浏览器访问格式	
				
				//判断平台
				if (plus.os.name == 'Android') {
					let openURL = androidPrefix + urls;
					//console.log("openURL:" + openURL);
					plus.runtime.openURL(openURL, err => {
						uni.showToast({
							title: "打开支付宝失败！请检查是否已安装？",
							icon: 'none'
						})
					}, 'com.eg.android.AlipayGphone')
				} else if (plus.os.name == 'iOS') {
					let openURL = iosPrefix + urls;
					plus.runtime.openURL(openURL, err => {
						uni.showToast({
							title: "打开支付宝失败！请检查是否已安装？",
							icon: 'none'
						})
					}, 'com.eg.android.AlipayGphone')
				}


			}
		}
	}
</script>

<style lang="scss">
	.binding-btn {
		width: 60%;
		height: 100rpx;
		margin-top: 40rpx;
		margin-left: 20%;
		border-radius: 60rpx;
		text-align: center;
		line-height: 100rpx;
		background-color: #4F7FFD;

		text {
			color: #fff;
			font-size: 32rpx;
		}
	}
</style>